'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('outfits', {
      id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      user_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: '用户ID',
        references: {
          model: 'users',
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE',
      },
      name: {
        type: Sequelize.STRING(100),
        allowNull: false,
        comment: '搭配名称',
      },
      description: {
        type: Sequelize.TEXT,
        allowNull: true,
        comment: '搭配描述',
      },
      style: {
        type: Sequelize.ENUM('casual', 'formal', 'business', 'sport', 'party', 'vintage', 'street'),
        allowNull: true,
        comment: '搭配风格',
      },
      occasion: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: '适用场合',
      },
      season: {
        type: Sequelize.ENUM('spring', 'summer', 'autumn', 'winter', 'all'),
        allowNull: true,
        comment: '适用季节',
      },
      weather: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: '适用天气',
      },
      color_scheme: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: '配色方案',
      },
      main_image: {
        type: Sequelize.STRING(255),
        allowNull: true,
        comment: '搭配主图',
      },
      images: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: '搭配图片',
      },
      rating: {
        type: Sequelize.DECIMAL(2, 1),
        allowNull: true,
        comment: '评分(1-5)',
      },
      wear_count: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
        comment: '穿着次数',
      },
      last_worn_date: {
        type: Sequelize.DATE,
        allowNull: true,
        comment: '最后穿着日期',
      },
      is_favorite: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
        comment: '是否收藏',
      },
      is_public: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
        comment: '是否公开',
      },
      tags: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: '标签',
      },
      notes: {
        type: Sequelize.TEXT,
        allowNull: true,
        comment: '备注',
      },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW,
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW,
      },
      deleted_at: {
        type: Sequelize.DATE,
        allowNull: true,
      },
    });

    // 添加索引
    await queryInterface.addIndex('outfits', ['user_id']);
    await queryInterface.addIndex('outfits', ['style']);
    await queryInterface.addIndex('outfits', ['season']);
    await queryInterface.addIndex('outfits', ['is_favorite']);
    await queryInterface.addIndex('outfits', ['is_public']);
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('outfits');
  },
};
